<template>
    <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
              :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
              :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
              :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
        <a-form ref="formRef" :model="formState" layout="vertical" :rules="CURRENCY_TARIFF_EDIT.RULES">
            <a-row :gutter="12">

                <a-col :span="24">
                    <a-form-item label="充值金额" field="payAmount">
                        <a-input-number :min="1" :precision="2"  v-model="formState.payAmount" allow-clear placeholder="请设置充值金额">

                            <template #append>
                                <span style="width: 50px">元</span>
                            </template>
                        </a-input-number>
                    </a-form-item>
                </a-col>

                <a-col :span="12">
                    <a-form-item label="获得数量" field="baseCoin">
                        <a-input-number  :min="1" v-model="formState.baseCoin" allow-clear placeholder="请设置获得数量"/>
                    </a-form-item>
                </a-col>


                <a-col :span="12">
                    <a-form-item label="赠送数量" field="bestowCoin" tooltip="如果不对充值进行赠送 那么数量请填写0">
                        <a-input-number :min="0" v-model="formState.bestowCoin" allow-clear placeholder="请设置赠送数量"/>
                    </a-form-item>
                </a-col>



                <a-col :span="24">
                    <a-form-item label="备注信息" field="description">
                        <a-textarea v-model="formState.description" :auto-size="{minRows:2 , maxRows:5}" allow-clear placeholder="备注信息"/>
                    </a-form-item>
                </a-col>


            </a-row>


        </a-form>
        <!--表单结束-->
    </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'

import {CURRENCY_TARIFF_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addTariff, updateTariff} = SystemHttp
const config = {tplRecord: CURRENCY_TARIFF_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addTariff).setUpdateRequest(updateTariff)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改充值定价' : '新建充值定价'
</script>
